

var oPage = {

	oThis: null,
	detail: null,

	init: function () {
		this.initState();
		this.initEvent();
	},

	initState: function () {
		this.oThis = $('#moldSeeWp');

		this.getDetail(); // 获取详情
	},

	initEvent: function () {

	},

	getDetail: function () {
		var dt = pb.storage.get('mold-detail');
		if (!dt) {
			return;
		}
		this.detail = dt;
		this.setDetailHtml();
	},

	// 根据detail设置内容
	setDetailHtml: function () {
		if (!this.detail) {
			return;
		}
		this.oThis.find('.sqdh-text').html(this.detail.applyNo);
		this.oThis.find('.sqks-text').html(this.detail.deptName);
		this.oThis.find('.sqys-text').html(this.detail.doctorName);
		this.oThis.find('.sqsj-text').html(this.detail.applyTime);

		this.oThis.find('.yxxx-text').html(this.detail.imageName);
		this.oThis.find('.hzxm-text').html(this.detail.patientName);
		this.oThis.find('.hzxb-text').html(this.detail.sex);
		this.oThis.find('.hznl-text').html(this.detail.age);
		this.oThis.find('.hzmz-text').html(this.detail.outpatientCode);
		this.oThis.find('.hzzy-text').html(this.detail.hospitalizedCode);
		this.oThis.find('.hzjc-text').html(this.detail.equipmentDetail);
		this.oThis.find('.hzyx-text').html(this.detail.imageCode);
		this.oThis.find('.dzbw-text').html(this.detail.partName);
		this.oThis.find('.jbzd-text').html(this.detail.diagnosisMark);
		this.oThis.find('.dzly-text').html(this.detail.reasonMark);
		this.oThis.find('.yxsjlx-text').html(pb.getNameByCode(this.detail.imageTypeCode, pb.yxsjlxList));
	
		this.setMoldStep(); // 设置申请步骤
		this.setCompletion(); // 步骤完成情况
	},

	// 设置申请步骤
	setMoldStep: function () {
		var _this = this;
		console.log(this.detail);
		var list = [
			{title: '文件接收', name: 'receiveUserName', time: 'receiveTime'},
			{title: '文件下载', name: 'downloadUserName', time: 'downloadTime'},
			{title: '制定计划', name: 'makeUserEndName', time: 'makeTime'},
			{title: '建模', name: 'modeUserEndName', time: 'modeActualTime'},
			{title: '制模', name: 'makeUserEndName', time: 'makeActualTime'},
			{title: '文件交付', name: 'fileReceiveUserName', time: 'fileReceiveTime'},
			{title: '实物交付', name: 'matterReceiveUserName', time: 'matterReceiveTime'},
		]
		var stateList = [
			{key: 'receiveState', val: 1},
			{key: 'downloadState', val: 1},
			{key: 'makePlanState', val: 1},
			{key: 'modeState', val: 2},
			{key: 'makeState', val: 2},
			{key: 'fileState', val: 2},
			{key: 'physicalState', val: 2}
		];
		var state = 0;
		for (var i = 0; i < stateList.length; i++) {
			var item = stateList[i];
			if (this.detail[item.key] != item.val) {
				state = i;
				break;
			}
		}
		if (i == stateList.length) {
			state = stateList.length;
		}

		var html = '';
		for (var i = 1; i <= list.length; i++) {
			var item = list[i-1];
			var type = 1, typeText = '待进行', text = '步骤的描述', icon = '';
			if (i <= state) {
				type = 3;
				typeText = '已完成';
				text = _this.detail[item.name] + '</br>' + _this.detail[item.time];
				icon = ' icon iconfont icongou';
			} else if (i == state+1) {
				type = 2;
				typeText = '进行中';
				icon = ' icon iconfont iconxia';
			}

			html += '<div class="item">' +
						'<span class="step-name">' + item.title + '</span>' +
						'<div class="icon-box">' +
							'<div class="type type' + type + '">' +
								'<span class="text' + icon + '">' + (type == 1 ? i : '') +  '</span>' +
								'<span class="left"></span>' +
								'<span class="right"></span>' +
							'</div>' +
						'</div>' +
						'<div class="text-box">' +
							'<span class="type">' + typeText + '</span>' +
							'<div class="descr"><p>' + text + '</p></div>' +
						'</div>' +
					'</div>';
		}
		this.oThis.find('.apply-step').html(html);
	},

	setCompletion: function () {
		var aCom = [
			{title: '文件接收', key: 'receiveState', val: [1], name: 'receiveUserName', time: 'receiveTime'},
			{title: '文件下载', key: 'downloadState', val: [1], name: 'downloadUserName', time: 'downloadTime'},
			{title: '制定计划', key: 'makePlanState', val: [1], name: 'makeUserEndName', time: 'makeTime'},
			{title: '建模开始', key: 'modeState', val: [1,2], name: 'modeUserStartName', time: 'modeActualStartTime'},
			{title: '建模完成', key: 'modeState', val: [2], name: 'modeUserEndName', time: 'modeActualEndTime'},
			{title: '制模开始', key: 'makeState', val: [1,2], name: 'makeUserStartName', time: 'makeActualStartTime'},
			{title: '制模完成', key: 'makeState', val: [2], name: 'makeUserEndName', time: 'makeActualEndTime'},
			{title: '模型文件上传', key: 'fileState', val: [1,2], name: 'fileUploadUserName', time: 'fileUploadTime'},
			{title: '模型文件接收', key: 'fileState', val: [2], name: 'fileReceiveUserName', time: 'fileReceiveTime'},
			{title: '模型实物发货', key: 'physicalState', val: [1,2], name: 'matterDeliverUserName', time: 'matterDeliverTime'},
			{title: '模型实物接收', key: 'physicalState', val: [2], name: 'matterReceiveUserName', time: 'matterReceiveTime'},
		];
		var html = '';
		for (var i = 0; i < aCom.length; i++) {
			var item = aCom[i];
			var isOk = item.val.indexOf(this.detail[item.key])!=-1;
			html += '<div class="item ' + (isOk ? '' : 'not') + '">' +
						'<div class="icon iconfont ' + (isOk ? 'icongou' : 'iconxia') + '"></div>' +
						'<div class="text-box clearfix">' +
							'<span class="title">' + item.title + '</span>' +
							'<span>' + (isOk ? this.detail[item.name] : '') + '</span>' +
							'<span>' + (isOk ? this.detail[item.time] : '') + '</span>' +
						'</div>' +
					'</div>';
		}
		this.oThis.find('.speed-info .list').html(html);
	}

}


$(function () {
	oPage.init();
})

